package com.kedou.sdk.ui.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.kedou.sdk.JuHaoWanSDK;
import com.kedou.sdk.assist.Constant;

import com.kedou.sdk.core.HttpEngineApi;
import com.kedou.sdk.core.HttpEngineConduits;
import com.kedou.sdk.params.bean.NavModel;
import com.kedou.sdk.params.bean.NoticePopup;
import com.kedou.sdk.params.bean.Popup;
import com.kedou.sdk.params.bean.WindowMessage;
import com.squareup.picasso.Picasso;

import java.util.List;


public class ActivityActivity extends AppBaseActivity {



    ImageView imageView;

    ImageView closeView;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutIdentifier("activity_activity"));
        imageView =   findViewById(getViewIdentifier("activity_image"));
        closeView =   findViewById(getViewIdentifier("activity_close"));
        Popup popup = getIntent().getParcelableExtra("pop");
        if(popup!=null){
            Picasso.with(ActivityActivity.this).load(popup.getImage()).into(imageView);
        }
//        ActivityModel model = (ActivityModel)getIntent().getSerializableExtra("model");
//        imageView.setMaxWidth(UIUtil.getScreenWidth(ActivityActivity.this)-40);
//        model.setImage("https://apk.iyingyao.com/01yx/file/upload/20240320/8254a954e9077ccfbaeda4ece6278abf.png");
//        GlideHelper.loadGoodsCover(Glide.with(imageView),imageView,model.getImage());
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(popup.getJump_type()==3){
                    WindowMessage message= new WindowMessage();
                    List<NavModel> models = JuHaoWanSDK.getInstance().getPlatformConfigInfo().getNav_list();
                    for (NavModel model:models) {
                        if(model.getIden_name().equals(popup.getJump_value())){
                            message.setNavModel(model);
                            Intent intent = new Intent(ActivityActivity.this, FloatExtensionBarActivity.class);
                            intent.setPackage(ActivityActivity.this.getPackageName());
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            intent.putExtra(Constant.LocalIntentExtra.INTENT_FLOAT_WINDOW_DATA, message);
                            startActivity(intent);
                            break;
                        }
                    }


                }else{

                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(popup.getJump_value())));
                }
                finish();
            }
        });
        closeView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    @Override
    protected void onDestroy() {
        HttpEngineConduits wanSDKDataDao = HttpEngineApi.getInstance().getEngineConduits();
        NoticePopup popup=wanSDKDataDao.getPlatformConfigInfo().getNotice_popup();
        if(popup!=null){
            Intent in = new Intent(ActivityActivity.this,NoticeActivity.class);
            in.putExtra("pop",popup);
            startActivity(in);
        }

        super.onDestroy();
    }
}
